package com.projectCommon.bean.easyExcel;


import java.util.Arrays;
import java.util.List;

//  这个对象被继承一下......  可以解决很多的问题，初始化数组和对象。简化很多的代码， 虽然这里复杂， 但是可以简化很多很多的代码
// 代码的话可能也没有简化很多，但是看起来很简单了
public class BaseGearInfo {
    // 档位数量
    public final static int levelNum = 30;
    // 初始化的数值
    private final static String initValue = "-1";
    // 档位的信息，不局限于数量和价格
    private String lv_30, lv_29, lv_28, lv_27, lv_26, lv_25, lv_24, lv_23, lv_22, lv_21, lv_20, lv_19, lv_18, lv_17, lv_16, lv_15, lv_14, lv_13, lv_12, lv_11, lv_10, lv_9, lv_8, lv_7, lv_6, lv_5, lv_4, lv_3, lv_2, lv_1;
    // 为上述所有的数据合集，初始化大小为30个
    protected String[] dataArray = new String[levelNum];

    public BaseGearInfo() {
        initDataArray();
        initGearLevels();
    }


    public BaseGearInfo(String lv_30, String lv_29, String lv_28, String lv_27, String lv_26, String lv_25, String lv_24, String lv_23, String lv_22, String lv_21, String lv_20, String lv_19, String lv_18, String lv_17, String lv_16, String lv_15, String lv_14, String lv_13, String lv_12, String lv_11, String lv_10, String lv_9, String lv_8, String lv_7, String lv_6, String lv_5, String lv_4, String lv_3, String lv_2, String lv_1) {
        initGearLevels(lv_30, lv_29, lv_28, lv_27, lv_26, lv_25, lv_24, lv_23, lv_22, lv_21, lv_20, lv_19, lv_18, lv_17, lv_16, lv_15, lv_14, lv_13, lv_12, lv_11, lv_10, lv_9, lv_8, lv_7, lv_6, lv_5, lv_4, lv_3, lv_2, lv_1);
        initDataArray(lv_30, lv_29, lv_28, lv_27, lv_26, lv_25, lv_24, lv_23, lv_22, lv_21, lv_20, lv_19, lv_18, lv_17, lv_16, lv_15, lv_14, lv_13, lv_12, lv_11, lv_10, lv_9, lv_8, lv_7, lv_6, lv_5, lv_4, lv_3, lv_2, lv_1);
    }

    public BaseGearInfo(String[] data) {
        if (data == null || data.length != levelNum) {
            throw new RuntimeException("传入档位信息异常");
        }
        initGearLevels(dataArray);
        initDataArray(dataArray);
    }

    public String getLv_30() {
        return lv_30;
    }

    public void setLv_30(String lv_30) {
        this.lv_30 = lv_30;
        updateDataArray(0, lv_30);
    }

    public String getLv_29() {
        return lv_29;
    }

    public void setLv_29(String lv_29) {
        this.lv_29 = lv_29;
        updateDataArray(1, lv_29);
    }

    public String getLv_28() {
        return lv_28;
    }

    public void setLv_28(String lv_28) {
        this.lv_28 = lv_28;
        updateDataArray(2, lv_28);
    }

    public String getLv_27() {
        return lv_27;
    }

    public void setLv_27(String lv_27) {
        this.lv_27 = lv_27;
        updateDataArray(3, lv_27);
    }

    public String getLv_26() {
        return lv_26;
    }

    public void setLv_26(String lv_26) {
        this.lv_26 = lv_26;
        updateDataArray(4, lv_26);
    }

    public String getLv_25() {
        return lv_25;
    }

    public void setLv_25(String lv_25) {
        this.lv_25 = lv_25;
        updateDataArray(5, lv_25);
    }

    public String getLv_24() {
        return lv_24;
    }

    public void setLv_24(String lv_24) {
        this.lv_24 = lv_24;
        updateDataArray(6, lv_24);
    }

    public String getLv_23() {
        return lv_23;
    }

    public void setLv_23(String lv_23) {
        this.lv_23 = lv_23;
        updateDataArray(7, lv_23);
    }

    public String getLv_22() {
        return lv_22;
    }

    public void setLv_22(String lv_22) {
        this.lv_22 = lv_22;
        updateDataArray(8, lv_22);
    }

    public String getLv_21() {
        return lv_21;
    }

    public void setLv_21(String lv_21) {
        this.lv_21 = lv_21;
        updateDataArray(9, lv_21);
    }

    public String getLv_20() {
        return lv_20;
    }

    public void setLv_20(String lv_20) {
        this.lv_20 = lv_20;
        updateDataArray(10, lv_20);
    }

    public String getLv_19() {
        return lv_19;
    }

    public void setLv_19(String lv_19) {
        this.lv_19 = lv_19;
        updateDataArray(11, lv_19);
    }

    public String getLv_18() {
        return lv_18;
    }

    public void setLv_18(String lv_18) {
        this.lv_18 = lv_18;
        updateDataArray(12, lv_18);
    }

    public String getLv_17() {
        return lv_17;
    }

    public void setLv_17(String lv_17) {
        this.lv_17 = lv_17;
        updateDataArray(13, lv_17);
    }

    public String getLv_16() {
        return lv_16;
    }

    public void setLv_16(String lv_16) {
        this.lv_16 = lv_16;
        updateDataArray(14, lv_16);
    }

    public String getLv_15() {
        return lv_15;
    }

    public void setLv_15(String lv_15) {
        this.lv_15 = lv_15;
        updateDataArray(15, lv_15);
    }

    public String getLv_14() {
        return lv_14;
    }

    public void setLv_14(String lv_14) {
        this.lv_14 = lv_14;
        updateDataArray(16, lv_14);
    }

    public String getLv_13() {
        return lv_13;
    }

    public void setLv_13(String lv_13) {
        this.lv_13 = lv_13;
        updateDataArray(17, lv_13);
    }

    public String getLv_12() {
        return lv_12;
    }

    public void setLv_12(String lv_12) {
        this.lv_12 = lv_12;
        updateDataArray(18, lv_12);
    }

    public String getLv_11() {
        return lv_11;
    }

    public void setLv_11(String lv_11) {
        this.lv_11 = lv_11;
        updateDataArray(19, lv_11);
    }

    public String getLv_10() {
        return lv_10;
    }

    public void setLv_10(String lv_10) {
        this.lv_10 = lv_10;
        updateDataArray(20, lv_10);
    }

    public String getLv_9() {
        return lv_9;
    }

    public void setLv_9(String lv_9) {
        this.lv_9 = lv_9;
        updateDataArray(21, lv_9);
    }

    public String getLv_8() {
        return lv_8;
    }

    public void setLv_8(String lv_8) {
        this.lv_8 = lv_8;
        updateDataArray(22, lv_8);
    }

    public String getLv_7() {
        return lv_7;
    }

    public void setLv_7(String lv_7) {
        this.lv_7 = lv_7;
        updateDataArray(23, lv_7);
    }

    public String getLv_6() {
        return lv_6;
    }

    public void setLv_6(String lv_6) {
        this.lv_6 = lv_6;
        updateDataArray(24, lv_6);
    }

    public String getLv_5() {
        return lv_5;
    }

    public void setLv_5(String lv_5) {
        this.lv_5 = lv_5;
        updateDataArray(25, lv_5);
    }

    public String getLv_4() {
        return lv_4;
    }

    public void setLv_4(String lv_4) {
        this.lv_4 = lv_4;
        updateDataArray(26, lv_4);
    }

    public String getLv_3() {
        return lv_3;
    }

    public void setLv_3(String lv_3) {
        this.lv_3 = lv_3;
        updateDataArray(27, lv_3);
    }

    public String getLv_2() {
        return lv_2;
    }

    public void setLv_2(String lv_2) {
        this.lv_2 = lv_2;
        updateDataArray(28, lv_2);
    }

    public String getLv_1() {
        return lv_1;
    }

    public void setLv_1(String lv_1) {
        this.lv_1 = lv_1;
        updateDataArray(29, lv_1);
    }

    public String[] getDataArray() {
        return dataArray;
    }

    public void setDataArray(String[] dataArray) {
        this.dataArray = dataArray;
    }

    // 针对一个数据的时候通过这种方式改，针对多个数据的时候，通过多个数组修改。
    public void setGearValue(int gear_lv, String value) {
        if (!(gear_lv >= 1 && gear_lv <= 30)) {
            throw new RuntimeException("数据异常");
        }
        updateDataArray(30 - gear_lv, value);
        initGearLevels(this.dataArray);
    }

    /**
     * 档位的值 从30开始到1
     *
     * @param values 档位的值
     */
    public void setData(String[] values) {
        if (values.length != 30) {
            throw new RuntimeException("数据异常");
        }
        for (int i = 0; i < values.length; i++) {
            updateDataArray(i, values[i]);
        }
        initGearLevels(this.dataArray);
    }

    //TODO: 这儿修改一下，改成档位，而不是索引！！谁知道索引是个什么
    public String getGearValue(int gearLv) {
        if (gearLv <= 0 || gearLv > levelNum) {
            throw new RuntimeException("没有当前数值");
        }
        return dataArray[30 - gearLv];
    }

    private void updateDataArray(int index, String value) {
        this.dataArray[index] = value;
    }

    private void initDataArray() {
        Arrays.fill(dataArray, initValue);
    }

    private void initDataArray(String lv_30, String lv_29, String lv_28, String lv_27, String lv_26, String lv_25, String lv_24, String lv_23, String lv_22, String lv_21, String lv_20, String lv_19, String lv_18, String lv_17, String lv_16, String lv_15, String lv_14, String lv_13, String lv_12, String lv_11, String lv_10, String lv_9, String lv_8, String lv_7, String lv_6, String lv_5, String lv_4, String lv_3, String lv_2, String lv_1) {
        this.dataArray[0] = lv_30;
        this.dataArray[1] = lv_29;
        this.dataArray[2] = lv_28;
        this.dataArray[3] = lv_27;
        this.dataArray[4] = lv_26;
        this.dataArray[5] = lv_25;
        this.dataArray[6] = lv_24;
        this.dataArray[7] = lv_23;
        this.dataArray[8] = lv_22;
        this.dataArray[9] = lv_21;
        this.dataArray[10] = lv_20;
        this.dataArray[11] = lv_19;
        this.dataArray[12] = lv_18;
        this.dataArray[13] = lv_17;
        this.dataArray[14] = lv_16;
        this.dataArray[15] = lv_15;
        this.dataArray[16] = lv_14;
        this.dataArray[17] = lv_13;
        this.dataArray[18] = lv_12;
        this.dataArray[19] = lv_11;
        this.dataArray[20] = lv_10;
        this.dataArray[21] = lv_9;
        this.dataArray[22] = lv_8;
        this.dataArray[23] = lv_7;
        this.dataArray[24] = lv_6;
        this.dataArray[25] = lv_5;
        this.dataArray[26] = lv_4;
        this.dataArray[27] = lv_3;
        this.dataArray[28] = lv_2;
        this.dataArray[29] = lv_1;
    }

    private void initDataArray(String[] dataArray) {
        if (dataArray == null || dataArray.length != levelNum) {
            throw new RuntimeException("数据传入异常");
        }
        this.dataArray[0] = dataArray[0];
        this.dataArray[1] = dataArray[1];
        this.dataArray[2] = dataArray[2];
        this.dataArray[3] = dataArray[3];
        this.dataArray[4] = dataArray[4];
        this.dataArray[5] = dataArray[5];
        this.dataArray[6] = dataArray[6];
        this.dataArray[7] = dataArray[7];
        this.dataArray[8] = dataArray[8];
        this.dataArray[9] = dataArray[9];
        this.dataArray[10] = dataArray[10];
        this.dataArray[11] = dataArray[11];
        this.dataArray[12] = dataArray[12];
        this.dataArray[13] = dataArray[13];
        this.dataArray[14] = dataArray[14];
        this.dataArray[15] = dataArray[15];
        this.dataArray[16] = dataArray[16];
        this.dataArray[17] = dataArray[17];
        this.dataArray[18] = dataArray[18];
        this.dataArray[19] = dataArray[19];
        this.dataArray[20] = dataArray[20];
        this.dataArray[21] = dataArray[21];
        this.dataArray[22] = dataArray[22];
        this.dataArray[23] = dataArray[23];
        this.dataArray[24] = dataArray[24];
        this.dataArray[25] = dataArray[25];
        this.dataArray[26] = dataArray[26];
        this.dataArray[27] = dataArray[27];
        this.dataArray[28] = dataArray[28];
        this.dataArray[29] = dataArray[29];
    }

    private void initGearLevels() {
        initGearLevels(dataArray);
    }

    private void initGearLevels(String lv_30, String lv_29, String lv_28, String lv_27, String lv_26, String lv_25, String lv_24, String lv_23, String lv_22, String lv_21, String lv_20, String lv_19, String lv_18, String lv_17, String lv_16, String lv_15, String lv_14, String lv_13, String lv_12, String lv_11, String lv_10, String lv_9, String lv_8, String lv_7, String lv_6, String lv_5, String lv_4, String lv_3, String lv_2, String lv_1) {
        this.lv_30 = lv_30;
        this.lv_29 = lv_29;
        this.lv_28 = lv_28;
        this.lv_27 = lv_27;
        this.lv_26 = lv_26;
        this.lv_25 = lv_25;
        this.lv_24 = lv_24;
        this.lv_23 = lv_23;
        this.lv_22 = lv_22;
        this.lv_21 = lv_21;
        this.lv_20 = lv_20;
        this.lv_19 = lv_19;
        this.lv_18 = lv_18;
        this.lv_17 = lv_17;
        this.lv_16 = lv_16;
        this.lv_15 = lv_15;
        this.lv_14 = lv_14;
        this.lv_13 = lv_13;
        this.lv_12 = lv_12;
        this.lv_11 = lv_11;
        this.lv_10 = lv_10;
        this.lv_9 = lv_9;
        this.lv_8 = lv_8;
        this.lv_7 = lv_7;
        this.lv_6 = lv_6;
        this.lv_5 = lv_5;
        this.lv_4 = lv_4;
        this.lv_3 = lv_3;
        this.lv_2 = lv_2;
        this.lv_1 = lv_1;
    }

    protected void initGearLevels(String[] dataArray) {
        this.lv_30 = dataArray[0];
        this.lv_29 = dataArray[1];
        this.lv_28 = dataArray[2];
        this.lv_27 = dataArray[3];
        this.lv_26 = dataArray[4];
        this.lv_25 = dataArray[5];
        this.lv_24 = dataArray[6];
        this.lv_23 = dataArray[7];
        this.lv_22 = dataArray[8];
        this.lv_21 = dataArray[9];
        this.lv_20 = dataArray[10];
        this.lv_19 = dataArray[11];
        this.lv_18 = dataArray[12];
        this.lv_17 = dataArray[13];
        this.lv_16 = dataArray[14];
        this.lv_15 = dataArray[15];
        this.lv_14 = dataArray[16];
        this.lv_13 = dataArray[17];
        this.lv_12 = dataArray[18];
        this.lv_11 = dataArray[19];
        this.lv_10 = dataArray[20];
        this.lv_9 = dataArray[21];
        this.lv_8 = dataArray[22];
        this.lv_7 = dataArray[23];
        this.lv_6 = dataArray[24];
        this.lv_5 = dataArray[25];
        this.lv_4 = dataArray[26];
        this.lv_3 = dataArray[27];
        this.lv_2 = dataArray[28];
        this.lv_1 = dataArray[29];
    }

    // 得有一个copy的逻辑。传入一个base的对象。 将对应的copy逻辑进行copy
    public void copyLevel(BaseGearInfo baseGearInfo) {
        initGearLevels(baseGearInfo.getDataArray());
        initDataArray(baseGearInfo.getDataArray());
    }

    public void copyLevel(List<String> lvList) {
        if (lvList.size() != levelNum) {
            throw new RuntimeException("档位数据异常");
        }
        String[] dataArray = new String[levelNum];
        for (int i = 0; i < dataArray.length; i++) {
            dataArray[i] = lvList.get(i);
        }
        initGearLevels(dataArray);
        initDataArray(dataArray);
    }
}
